﻿using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;
using KPIS.GERP.Models.ICM;
using KPIS.GERP.Models;

namespace KPIS.GERP.WEB.GIMS.Controllers
{
    [AccessDeniedAuthorize]
    public class SampleIcmReceivedEditedController : Controller
    {
        private GERPContext db = new GERPContext();

        //
        // GET: /SampleIcmReceived/

        public ActionResult Index()
        {
            var receives = db.Receiveds.Include(r => r.Warehouse);
            return View(receives.ToList());
        }

        //
        // GET: /SampleIcmReceived/Details/5

        public ActionResult Details(int id = 0)
        {
            Received received = db.Receiveds.Find(id);
            if (received == null)
            {
                return HttpNotFound();
            }
            return View(received);
        }

        //
        // GET: /SampleIcmReceived/Create

        public ActionResult Create()
        {
            ViewBag.WarehouseId = new SelectList(db.Warehouses, "WarehouseId", "WarehouseName");
            return View();
        }

        //
        // POST: /SampleIcmReceived/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Received received)
        {
            if (ModelState.IsValid)
            {
                db.Receiveds.Add(received);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.WarehouseId = new SelectList(db.Warehouses, "WarehouseId", "WarehouseName", received.WhId);
            return View(received);
        }

        //
        // GET: /SampleIcmReceived/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Received received = db.Receiveds.Find(id);
            if (received == null)
            {
                return HttpNotFound();
            }
            ViewBag.WarehouseId = new SelectList(db.Warehouses, "WarehouseId", "WarehouseName", received.WhId);
            return View(received);
        }

        //
        // POST: /SampleIcmReceived/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Received received)
        {
            if (ModelState.IsValid)
            {
                db.Entry(received).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.WarehouseId = new SelectList(db.Warehouses, "WarehouseId", "WarehouseName", received.WhId);
            return View(received);
        }

        //
        // GET: /SampleIcmReceived/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Received received = db.Receiveds.Find(id);
            if (received == null)
            {
                return HttpNotFound();
            }
            return View(received);
        }

        //
        // POST: /SampleIcmReceived/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Received received = db.Receiveds.Find(id);
            db.Receiveds.Remove(received);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}